﻿using Easy.Services.DbContexts;
using Easy.Services.Entities;
using Easy.Services.Interface;
using System.Linq.Expressions;

namespace Easy.Services.Core
{
    internal class PermissionService: IPermissionService
    {
        public Permission Add(Permission permission)
        {
            using MySQLDbContext db = new();
            BaseService<Permission> baseService = new(db);
            baseService.AddBase(permission);
            return permission;

        }

        public Permission Get(Expression<Func<Permission, bool>> expression)
        {
            using MySQLDbContext db = new();
            BaseService<Permission> baseService = new(db);
            return baseService.GetBase(expression);

        }

        public Permission Update(Permission  permission)
        {
            using MySQLDbContext db = new();
            BaseService<Permission> baseService = new(db);
            baseService.UpdateBase(permission);
            return permission;

        }

        public bool Delete(Permission permission)
        {
            using MySQLDbContext db = new();
            BaseService<Permission> baseService = new(db);
            permission.IsDelete = true;
            return baseService.UpdateBase(permission);

        }

        public List<Permission> GetList(Expression<Func<Permission, bool>> whereExpression = null, bool includeDelete = false)
        {
            using MySQLDbContext db = new();
            BaseService<Permission> baseService = new(db);
            return baseService.GetListBase(whereExpression, includeDelete);

        }

        public bool Exist(Expression<Func<Permission, bool>> expression)
        {
            using MySQLDbContext db = new();
            BaseService<Permission> baseService = new(db);
            return baseService.Exist(expression);

        }


    }

}
